package leetcode;

/**
 * Created by lianglab on 2018/3/23.
 */
public class Climb {
    /**
     * You are climbing a stair case. It takes n steps to reach to the top.
     Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
     动归 d[i] = d[i-1]+d[i-2]; d[1] = 1, d[2] = 2;

     * @param n
     * @return
     */
    public int climbStairs(int n) {
        if(n == 1)
            return 1;
        if (n==2)
            return 2;
        int pre = 2, prepre = 1;
        int result = 0;
        for(int i=3;i<=n;i++){
            result = pre+prepre;
            prepre = pre;
            pre = result;
        }
        return result;
    }
}
